#-*- coding:utf-8 -*-
from tkinter import *
from tkinter.ttk import *
from database_module import *
import tkinter.messagebox
import sqlite3
import csv
 
class Main:
    def __init__(self,master):
        self.abas = Notebook(master)
        self.frame_aba1 = Frame(self.abas)
        self.frame_aba2 = Frame(self.abas)
        self.frame_aba3 = Frame(self.abas)
        menu1 = Menu(master)
        parte_menu = Menu(menu1)
        parte_menu.add_command(label="Salvar Tela",command=self.salvar)
        menu1.add_cascade(label="Opções",menu=parte_menu)
        master.config(menu=menu1)
        
        #Aba1
        self.labe1 = Label(self.frame_aba1,text="Latitude")
        self.labe1.place(x=1,y=8)
        self.lat = Entry(self.frame_aba1,width=20)
        self.lat.place(x=1,y=25)
        
        #----------------------------
        self.labe2 = Label(self.frame_aba1,text="Logitude")
        self.labe2.place(x=140,y=8)
        self.log = Entry(self.frame_aba1,width=20)
        self.log.place(x=140,y=25)
        
        #---------------------------------
        self.labe3 = Label(self.frame_aba1,text="Nome")
        self.labe3.place(x=280,y=8)
        self.nome1 = Entry(self.frame_aba1,width=50)
        self.nome1.place(x=280,y=25)
        #-----------------------------------------
        self.labe4 = Label(self.frame_aba1,text="Área de Drenagem (Km²)")
        self.labe4.place(x=1,y=60)
        self.area = Entry(self.frame_aba1,width=20)
        self.area.place(x=1,y=80)
        #------------------------------------
        self.labe5 = Label(self.frame_aba1,text="Cidade")
        self.labe5.place(x=740,y=8)
        self.cidade = Entry(self.frame_aba1,width=20)
        self.cidade.place(x=740,y=25)
        #------------------------------------------------
        self.labe6 = Label(self.frame_aba1,text="UF")
        self.labe6.place(x=880,y=8)
        self.uf = Entry(self.frame_aba1,width=10)
        self.uf.place(x=880,y=25)
        #----------------------------------------
        self.guardar2 = Button(self.frame_aba1,text="Inserir na Tabela",command=self.adicionar1)
        self.guardar2.place(x=350,y=80)
        self.apagar = Button(self.frame_aba1,text="Apagar Itens Selecionados",command=self.apagar)
        self.apagar.place(x=450,y=80)
        self.limpar = Button(self.frame_aba1,text="Limpar todos os campos",command=self.limpar)
        self.limpar.place(x=600,y=80)

        #------------------------------------------
        self.labe7 = Label(self.frame_aba1,text="Data da Coleta")
        self.labe7.place(x=600,y=8)
        self.data = Entry(self.frame_aba1,width=20)
        self.data.place(x=600,y=25)
        #-------------------------------------
        self.var = StringVar()
        self.var.set("    ")
        self.opt = OptionMenu(self.frame_aba1,self.var,"     ","Rio","Açude","lago","Outros")
        self.opt.place(x=190,y=80)
        self.labe8 = Label(self.frame_aba1,text="Local da Coleta")
        self.labe8.place(x=160,y=60)
        #------------------------------------------
        self.labe8 = Label(self.frame_aba1,text="Latitude")
        self.labe8.place(x=20,y=170)
        self.labe9 = Label(self.frame_aba1,text="Longitude ")
        self.labe9.place(x=140,y=170)
        self.labe10 = Label(self.frame_aba1,text="Nome")
        self.labe10.place(x=320,y=170)
        self.labe11 = Label(self.frame_aba1,text="Área")
        self.labe11.place(x=600,y=170)
        self.labe12 = Label(self.frame_aba1,text="Data")
        self.labe12.place(x=488,y=170)
        self.labe13 = Label(self.frame_aba1,text="UF")
        self.labe13.place(x=850,y=170)
        self.labe14 = Label(self.frame_aba1,text="Cidade")
        self.labe14.place(x=715,y=170)
        self.labe15 = Label(self.frame_aba1,text="Local")
        self.labe15.place(x=958,y=170)
        
        #listbox
        #---------------lat
        scrollbar = Scrollbar(self.frame_aba1)
        scrollbar.place(x=103,y=200)
        self.listbox = Listbox(self.frame_aba1,height=10,width=15)
        self.listbox.place(x=1,y=200)
        self.listbox.config(yscrollcommand=scrollbar.set)
        scrollbar.config(command=self.listbox.yview)
        #------------long
        scrollbar2 = Scrollbar(self.frame_aba1)
        scrollbar2.place(x=219,y=200)
        self.listbox2 = Listbox(self.frame_aba1,height=10,width=15)
        self.listbox2.place(x=120,y=200)
        self.listbox2.config(yscrollcommand=scrollbar2.set)
        scrollbar2.config(command=self.listbox2.yview)
        #-----------nome
        scrollbar3 = Scrollbar(self.frame_aba1)
        scrollbar3.place(x=430,y=200)
        self.listbox3 = Listbox(self.frame_aba1,height=10,width=30)
        self.listbox3.place(x=240,y=200)
        self.listbox3.config(yscrollcommand=scrollbar3.set)
        scrollbar3.config(command=self.listbox3.yview)
        #--------------área
        scrollbar4 = Scrollbar(self.frame_aba1,)
        scrollbar4.place(x=549,y=200)
        self.listbox4 = Listbox(self.frame_aba1,height=10,width=15)
        self.listbox4.place(x=450,y=200)
        self.listbox4.config(yscrollcommand=scrollbar4.set)
        scrollbar4.config(command=self.listbox4.yview)
        #-------------------------------data
        scrollbar5 = Scrollbar(self.frame_aba1)
        scrollbar5.place(x=670,y=200)
        self.listbox5 = Listbox(self.frame_aba1,height=10,width=15)
        self.listbox5.place(x=570,y=200)
        self.listbox5.config(yscrollcommand=scrollbar5.set)
        scrollbar5.config(command=self.listbox5.yview)
        #-------------------------------uf
        scrollbar6 = Scrollbar(self.frame_aba1)
        scrollbar6.place(x=908,y=200)
        self.listbox6 = Listbox(self.frame_aba1,height=10,width=15)
        self.listbox6.place(x=810,y=200)
        self.listbox6.config(yscrollcommand=scrollbar6.set)
        scrollbar5.config(command=self.listbox6.yview)
        #-------------------------------cidade
        scrollbar7 = Scrollbar(self.frame_aba1)
        scrollbar7.place(x=790,y=200)
        self.listbox7 = Listbox(self.frame_aba1,height=10,width=15)
        self.listbox7.place(x=692,y=200)
        self.listbox7.config(yscrollcommand=scrollbar7.set)
        scrollbar7.config(command=self.listbox5.yview)
        #-------------------------------local da coleta
        scrollbar8 = Scrollbar(self.frame_aba1)
        scrollbar8.place(x=1027,y=200)
        self.listbox8 = Listbox(self.frame_aba1,height=10,width=15)
        self.listbox8.place(x=928,y=200)
        self.listbox8.config(yscrollcommand=scrollbar8.set,)
        scrollbar8.config(command=self.listbox8.yview)
        #Aba2--------------------------------------------------------
        self.labe16 = Label(self.frame_aba2,text="Ph")
        self.labe16.place(x=20,y=8)
        self.ph = Entry(self.frame_aba2,width=10)
        self.ph.place(x=1,y=25)
        #-------------------------------
        self.labe17 = Label(self.frame_aba2,text="Temperatura do ar °C")
        self.labe17.place(x=80,y=8)
        self.temp = Entry(self.frame_aba2,width=10)
        self.temp.place(x=100,y=25)
        #-----------------------
        self.labe18 = Label(self.frame_aba2,text="Temperatura da água °C")
        self.labe18.place(x=220,y=8)
        self.tempag = Entry(self.frame_aba2,width=10)
        self.tempag.place(x=240,y=25)
        #------------------------------------------
        self.labe19 = Label(self.frame_aba2,text="Comdutividade Eletrica ms/cm")
        self.labe19.place(x=380,y=8)
        self.cond = Entry(self.frame_aba2,width=10)
        self.cond.place(x=430,y=25)
        #---------------------------------------------------
        self.labe20 = Label(self.frame_aba2,text="Turbidez NTU")
        self.labe20.place(x=585,y=8)
        self.turb = Entry(self.frame_aba2,width=10)
        self.turb.place(x=590,y=25)
        #-----------------------
        self.labe21 = Label(self.frame_aba2,text="Oxigênio Dissolvido mg/L")
        self.labe21.place(x=700,y=8)
        self.ox = Entry(self.frame_aba2,width=10)
        self.ox.place(x=740,y=25)
        #------------------------------
        self.labe22 = Label(self.frame_aba2,text="Sólidos totais mg/L")
        self.labe22.place(x=880,y=8)
        self.soli = Entry(self.frame_aba2,width=10)
        self.soli.place(x=900,y=25)
        #---------------------------------
        self.labe23 = Label(self.frame_aba2,text="Coliforme fecais totais nmp/100ml")
        self.labe23.place(x=1,y=60)
        self.coli = Entry(self.frame_aba2,width=10)
        self.coli.place(x=50,y=80)
        #---------------------------------------
        self.labe24 = Label(self.frame_aba2,text="Nitratos totais mg/l N")
        self.labe24.place(x=220,y=60)
        self.nitri = Entry(self.frame_aba2,width=10)
        self.nitri.place(x=240,y=80)
        #---------------------------------Butões da aba2 >>>>>>nessa parte vai aver outros paranmetros q serão chamados por outra janela
        #(paramentros : Cálcio - mmolc/L,Magnésio -  mmolc/L,Sódio -  mmolc/L,Potássio -  mmolc/L,Carbonatos -  mmolc/L
        #Bicarbonatos -  mmolc/L,Sulfatos -  mmolc/L,Cloretos -  mmolc/L,SOMA -  mmolc/L
        
        self.maispaaranmetro = Button(self.frame_aba2,text="Mais Parâmetros",command=self.nova)
        self.maispaaranmetro.place(x=650,y=80)
        self.incerir = Button(self.frame_aba2,text="Inserir na Tabela",command=self.adicionar2)
        self.incerir.place(x=1,y=110)
        self.apagar2 = Button(self.frame_aba2,text="Apagar Itens Selecionados",command=self.apagar2)
        self.apagar2.place(x=100,y=110)
        self.limpar2 = Button(self.frame_aba2,text="Limpar todos os campos",command=self.limpar2)
        self.limpar2.place(x=250,y=110)
#--------------------------------------------
        self.var2 = StringVar(self.frame_aba2)
        self.var2.set("Coleta")
        self.opt2 = OptionMenu(self.frame_aba2,self.var2,"       ","Margem Direito","Margem Esquerda","Centro")
        self.opt2.place(x=400,y=80)
        self.labe25 = Label(self.frame_aba2,text="Coleta")
        self.labe25.place(x=410,y=60)
        self.var3 = StringVar(self.frame_aba2)
        self.var3.set("Profundidade")
        self.opt2 = OptionMenu(self.frame_aba2,self.var3,"      ","Superfície","Sub Superfície","Fundo")
        self.opt2.place(x=530,y=80)
        self.labe26 = Label(self.frame_aba2,text="Profundidade")
        self.labe26.place(x=530,y=60)
        
        #listbox aba2 
        #---------------ph
        self.labe27 = Label(self.frame_aba2,text="Ph")
        self.labe27.place(x=15,y=180)
        scrollbar9 = Scrollbar(self.frame_aba2)
        scrollbar9.place(x=50,y=200)
        self.listbox9 = Listbox(self.frame_aba2,height=10,width=7)
        self.listbox9.place(x=1,y=200)
        self.listbox9.config(yscrollcommand=scrollbar9.set)
        scrollbar9.config(command=self.listbox9.yview)
        #------------Temperatura do ar °C
        self.labe28 = Label(self.frame_aba2,text="Temperatura \n do ar °C")
        self.labe28.place(x=70,y=160)
        scrollbar10 = Scrollbar(self.frame_aba2)
        scrollbar10.place(x=125,y=200)
        self.listbox10 = Listbox(self.frame_aba2,height=10,width=7)
        self.listbox10.place(x=80,y=200)
        self.listbox10.config(yscrollcommand=scrollbar10.set)
        scrollbar10.config(command=self.listbox10.yview)
        #-----------Temperatura da água °C
        self.labe29 = Label(self.frame_aba2,text="Temperatura \n da água °C")
        self.labe29.place(x=150,y=160)
        scrollbar11 = Scrollbar(self.frame_aba2)
        scrollbar11.place(x=199,y=200)
        self.listbox11 = Listbox(self.frame_aba2,height=10,width=7)
        self.listbox11.place(x=150,y=200)
        self.listbox11.config(yscrollcommand=scrollbar11.set)
        scrollbar11.config(command=self.listbox11.yview)
        #---------------------------------------------Comdutividade Eletrica ms/cm
        self.labe30 = Label(self.frame_aba2,text="Comdutividade Eletrica\n ms/cm")
        self.labe30.place(x=230,y=160)
        scrollbar12 = Scrollbar(self.frame_aba2)
        scrollbar12.place(x=298,y=200)
        self.listbox12 = Listbox(self.frame_aba2,height=10,width=7)
        self.listbox12.place(x=250,y=200)
        self.listbox12.config(yscrollcommand=scrollbar12.set)
        scrollbar12.config(command=self.listbox12.yview)
        #-------------------------------Turbidez NTU
        self.labe31 = Label(self.frame_aba2,text="Turbidez \n NTU")
        self.labe31.place(x=380,y=160)
        scrollbar13 = Scrollbar(self.frame_aba2)
        scrollbar13.place(x=428,y=200)
        self.listbox13 = Listbox(self.frame_aba2,height=10,width=7)
        self.listbox13.place(x=380,y=200)
        self.listbox13.config(yscrollcommand=scrollbar13.set)
        scrollbar13.config(command=self.listbox13.yview)
        #----------------------------Oxigênio Dissolvido mg/L
        self.labe32 = Label(self.frame_aba2,text="Oxigênio Dissolvido \n mg/L")
        self.labe32.place(x=450,y=160)
        scrollbar14 = Scrollbar(self.frame_aba2)
        scrollbar14.place(x=528,y=200)
        self.listbox14 = Listbox(self.frame_aba2,height=10,width=7)
        self.listbox14.place(x=480,y=200)
        self.listbox14.config(yscrollcommand=scrollbar14.set)
        scrollbar14.config(command=self.listbox14.yview)
        #------------------------------Sólidos totais mg/L
        self.labe33 = Label(self.frame_aba2,text="Sólidos totais \n mg/L")
        self.labe33.place(x=578,y=160)
        scrollbar15 = Scrollbar(self.frame_aba2)
        scrollbar15.place(x=628,y=200)
        self.listbox15 = Listbox(self.frame_aba2,height=10,width=7)
        self.listbox15.place(x=580,y=200)
        self.listbox15.config(yscrollcommand=scrollbar15.set)
        scrollbar15.config(command=self.listbox15.yview)
        #-----------------------------Coliforme fecais totais nmp/100ml
        self.labe34 = Label(self.frame_aba2,text="Coliforme fecais \n totais nmp/100ml")
        self.labe34.place(x=678,y=160)
        scrollbar16 = Scrollbar(self.frame_aba2)
        scrollbar16.place(x=728,y=200)
        self.listbox16 = Listbox(self.frame_aba2,height=10,width=7)
        self.listbox16.place(x=678,y=200)
        self.listbox16.config(yscrollcommand=scrollbar16.set,)
        scrollbar16.config(command=self.listbox16.yview)
        #----------------------------------------------------Nitratos totais mg/l N
        self.labe35 = Label(self.frame_aba2,text="Nitratos totais \n mg/l N")
        self.labe35.place(x=800,y=160)
        scrollbar17 = Scrollbar(self.frame_aba2)
        scrollbar17.place(x=848,y=200)
        self.listbox17 = Listbox(self.frame_aba2,height=10,width=7)
        self.listbox17.place(x=800,y=200)
        self.listbox17.config(yscrollcommand=scrollbar17.set,)
        scrollbar17.config(command=self.listbox17.yview)
         #----------------------------------------------------Coleta
        self.labe36 = Label(self.frame_aba2,text="Coleta")
        self.labe36.place(x=890,y=180)
        scrollbar18 = Scrollbar(self.frame_aba2)
        scrollbar18.place(x=938,y=200)
        self.listbox18 = Listbox(self.frame_aba2,height=10,width=7)
        self.listbox18.place(x=890,y=200)
        self.listbox18.config(yscrollcommand=scrollbar18.set,)
        scrollbar18.config(command=self.listbox18.yview)
         #----------------------------------------------------profundidade
        self.labe39 = Label(self.frame_aba2,text="Profundidade")
        self.labe39.place(x=968,y=180)
        scrollbar19 = Scrollbar(self.frame_aba2)
        scrollbar19.place(x=1028,y=200)
        self.listbox19 = Listbox(self.frame_aba2,height=10,width=7)
        self.listbox19.place(x=978,y=200)
        self.listbox19.config(yscrollcommand=scrollbar19.set,)
        scrollbar19.config(command=self.listbox19.yview)
        
   
  #Titulo das Abas
        self.abas.add(self.frame_aba1,text="Registro")
        self.abas.add(self.frame_aba2,text="Qualidade da Agua")
        self.abas.pack(ipadx=398,ipady=177)
        
   #Banco de Dados da aba1
        self.conectar = sqlite3.connect("dados.db")
        self.cur = self.conectar.cursor()
        self.cur.execute("CREATE TABLE IF NOT EXISTS lat(lati REAL)")
        self.conectar.commit()
        lista = self.cur.execute("SELECT * FROM lat")
        for i in lista:
            self.listbox.insert(END,i)
        self.cur.execute("CREATE TABLE IF NOT EXISTS long(longi REAL)")
        self.conectar.commit()
        lista1 = self.cur.execute("SELECT * FROM long")
        for i in lista1:
            self.listbox2.insert(END,i)
        self.cur.execute("CREATE TABLE IF NOT EXISTS nomes(nome TEXT)")
        self.conectar.commit()
        lista2 = self.cur.execute("SELECT * FROM nomes")
        for i in lista2:
            self.listbox3.insert(END,i)
        self.cur.execute("CREATE TABLE IF NOT EXISTS dat(data TEXT)")
        self.conectar.commit()
        lista3 = self.cur.execute("SELECT * FROM dat")
        for i in lista3:
            self.listbox4.insert(END,i)
        self.cur.execute("CREATE TABLE IF NOT EXISTS area(area REAL)")
        self.conectar.commit()
        lista4 = self.cur.execute("SELECT * FROM area")
        for i in lista4:
            self.listbox5.insert(END,i)
        self.cur.execute("CREATE TABLE IF NOT EXISTS local(local TEXT)")
        self.conectar.commit()
        lista5 = self.cur.execute("SELECT * FROM local")
        for i in lista5:
            self.listbox8.insert(END,i)
        self.cur.execute("CREATE TABLE IF NOT EXISTS cidade(cidade TEXT)")
        self.conectar.commit()
        lista6 = self.cur.execute("SELECT * FROM cidade")
        for i in lista6:
            self.listbox7.insert(END,i)
        self.cur.execute("CREATE TABLE IF NOT EXISTS uf(uf TEXT)")
        self.conectar.commit()
        lista7 = self.cur.execute("SELECT * FROM uf")
        for i in lista7:
            self.listbox6.insert(END,i)
#----------------------------------
 #Banco de dados da aba2
        self.cur.execute("CREATE TABLE IF NOT EXISTS ph(ph REAL)")
        self.conectar.commit()
        lista8 = self.cur.execute("SELECT * FROM ph")
        for i in lista8:
            self.listbox9.insert(END,i)
        self.cur.execute("CREATE TABLE IF NOT EXISTS tempar(tempar REAL)")
        self.conectar.commit()
        lista9 = self.cur.execute("SELECT * FROM tempar")
        for i in lista9:
            self.listbox10.insert(END,i)
        self.cur.execute("CREATE TABLE IF NOT EXISTS tempag(tempag REAL)")
        self.conectar.commit()
        lista10 = self.cur.execute("SELECT * FROM tempag")
        for i in lista10:
            self.listbox11.insert(END,i)
        self.cur.execute("CREATE TABLE IF NOT EXISTS condutelectre(condutelectre REAL)")
        self.conectar.commit()
        lista11 = self.cur.execute("SELECT * FROM condutelectre")
        for i in lista11:
            self.listbox12.insert(END,i)
        self.cur.execute("CREATE TABLE IF NOT EXISTS turb(turb REAL)")
        self.conectar.commit()
        lista12 = self.cur.execute("SELECT * FROM turb")
        for i in lista12:
            self.listbox13.insert(END,i)
        self.cur.execute("CREATE TABLE IF NOT EXISTS oxedis(oxedis REAL)")
        self.conectar.commit()
        lista13 = self.cur.execute("SELECT * FROM oxedis")
        for i in lista13:
            self.listbox14.insert(END,i)
        self.cur.execute("CREATE TABLE IF NOT EXISTS solidtotal(solidtotal REAL)")
        self.conectar.commit()
        lista14 = self.cur.execute("SELECT * FROM solidtotal")
        for i in lista14:
            self.listbox15.insert(END,i)
        self.cur.execute("CREATE TABLE IF NOT EXISTS colifortotal(colifortotal REAL)")
        self.conectar.commit()
        lista15 = self.cur.execute("SELECT * FROM colifortotal")
        for i in lista15:
            self.listbox16.insert(END,i)
        self.cur.execute("CREATE TABLE IF NOT EXISTS nitritotal(nitritotal REAL)")
        self.conectar.commit()
        lista16 = self.cur.execute("SELECT * FROM nitritotal")
        for i in lista16:
            self.listbox17.insert(END,i)
        self.cur.execute("CREATE TABLE IF NOT EXISTS coleta(coleta TXT)")
        self.conectar.commit()
        lista17 = self.cur.execute("SELECT * FROM coleta")
        for i in lista17:
            self.listbox18.insert(END,i)
        self.cur.execute("CREATE TABLE IF NOT EXISTS profundi(profundi TXT)")
        self.conectar.commit()
        lista18 = self.cur.execute("SELECT * FROM profundi") 
        for i in lista18:
            self.listbox19.insert(END,i)
    #----------------------------------------------------mais parametros 
        
    
        #Comandos
    def adicionar1(self):
        adicionar1 = self.lat.get()
        adicionar2 = self.log.get()
        nome2 = self.nome1.get()
        data1 = self.data.get()
        area1 = self.area.get()
        uf = self.uf.get()
        local = self.var.get()
        cidade = self.cidade.get()
        if adicionar1 == "" and adicionar2 == "" and nome2 == "" and data1 == "" and area1 == "" and uf == "" and cidade =="":
            tkinter.messagebox.showwarning("error","Porfavor preencha \n todos os campos coretamente.")
        else:
            self.cur.execute("insert into lat values (?)",(adicionar1,))
            self.conectar.commit()
            self.listbox.insert(END,adicionar1)
            self.cur.execute("insert into long values (?)",(adicionar2,))
            self.conectar.commit()
            self.listbox2.insert(END,adicionar2)
            self.cur.execute("insert into nomes values (?)",(nome2,))
            self.conectar.commit()
            self.listbox3.insert(END,nome2)
            self.cur.execute("insert into dat values (?)",(data1,))
            self.conectar.commit()
            self.listbox4.insert(END,data1)
            self.cur.execute("insert into area values (?)",(area1,))
            self.conectar.commit()
            self.listbox5.insert(END,area1)
            self.cur.execute("insert into uf values (?)",(uf,))
            self.conectar.commit()
            self.listbox6.insert(END,uf)
            self.cur.execute("insert into cidade values (?)",(cidade,))
            self.conectar.commit()
            self.listbox7.insert(END,cidade)
            self.cur.execute("insert into local values (?)",(local,))
            self.conectar.commit()
            self.listbox8.insert(END,local)
    def limpar (self):
         self.lat.delete(0,END)
         self.log.delete(0,END)
         self.nome1.delete(0,END)
         self.data.delete(0,END)
         self.area.delete(0,END)
         self.uf.delete(0,END)
         self.cidade.delete(0,END)
#------------------------------------------------
    def apagar(self):
        latx = str(self.listbox.get(ACTIVE))
        longx = str(self.listbox2.get(ACTIVE))
        nomex = str(self.listbox3.get(ACTIVE))
        datax = str(self.listbox4.get(ACTIVE))
        areax = str(self.listbox5.get(ACTIVE))
        ufx = str(self.listbox6.get(ACTIVE))
        cidadex = str(self.listbox7.get(ACTIVE))
        localx = str(self.listbox8.get(ACTIVE))
        
        self.cur.execute("DELETE FROM lat WHERE lati=?",[latx])
        self.conectar.commit()
        self.listbox.delete(ANCHOR)
        self.cur.execute("DELETE FROM long WHERE longi=?",[longx])
        self.conectar.commit()
        self.listbox2.delete(ANCHOR)
        self.cur.execute("DELETE FROM nomes WHERE nome=?",[nomex])
        self.conectar.commit()
        self.listbox3.delete(ANCHOR)
        self.cur.execute("DELETE FROM dat WHERE data=?",[datax])
        self.conectar.commit()
        self.listbox4.delete(ANCHOR)
        self.cur.execute("DELETE FROM area WHERE area=?",[areax])
        self.conectar.commit()
        self.listbox5.delete(ANCHOR)
        self.cur.execute("DELETE FROM uf WHERE uf=?",[ufx])
        self.conectar.commit()
        self.listbox6.delete(ANCHOR)
        self.cur.execute("DELETE FROM cidade WHERE cidade=?",[cidadex])
        self.conectar.commit()
        self.listbox7.delete(ANCHOR)
        self.cur.execute("DELETE FROM local WHERE local=?",[localx])
        self.conectar.commit()
        self.listbox8.delete(ANCHOR)
    def adicionar2(self):
        a = self.ph.get()
        b = self.temp.get()
        c = self.tempag.get()
        d = self.cond.get()
        f = self.turb.get()
        g = self.ox.get()
        h = self.soli.get()
        i = self.coli.get()
        j = self.nitri.get()
        l = self.var2.get()
        m = self.var3.get()
        if a == "" and b == "" and c == "" and d == "" and f == "" and g == "" and h == "" and i == "" and j == "":
            tkinter.messagebox.showwarning("error","Porfavor preencha \n todos os campos coretamente.")
        else:
            self.cur.execute("insert into ph values (?)",(a,))
            self.conectar.commit()
            self.listbox9.insert(END,a)
            self.cur.execute("insert into tempar values (?)",(b,))
            self.conectar.commit()
            self.listbox10.insert(END,b)
            self.cur.execute("insert into tempag values (?)",(c,))
            self.conectar.commit()
            self.listbox11.insert(END,c)
            self.cur.execute("insert into condutelectre values (?)",(d,))
            self.conectar.commit()
            self.listbox12.insert(END,d)
            self.cur.execute("insert into turb values (?)",(f,))
            self.conectar.commit()
            self.listbox13.insert(END,f)
            self.cur.execute("insert into oxedis values (?)",(g,))
            self.conectar.commit()
            self.listbox14.insert(END,g)
            self.cur.execute("insert into solidtotal values (?)",(h,))
            self.conectar.commit()
            self.listbox15.insert(END,h)
            self.cur.execute("insert into colifortotal values (?)",(i,))
            self.conectar.commit()
            self.listbox16.insert(END,i)
            self.cur.execute("insert into nitritotal values (?)",(j,))
            self.conectar.commit()
            self.listbox17.insert(END,j)
            self.cur.execute("insert into coleta values (?)",(l,))
            self.conectar.commit()
            self.listbox18.insert(END,l)
            self.cur.execute("insert into profundi values (?)",(m,))
            self.conectar.commit()
            self.listbox19.insert(END,m)
#-----------------------------------------------------------------------------------------
    def limpar2 (self):
         self.ph.delete(0,END)
         self.temp.delete(0,END)
         self.tempag.delete(0,END)
         self.cond.delete(0,END)
         self.turb.delete(0,END)
         self.ox.delete(0,END)
         self.soli.delete(0,END)
         self.coli.delete(0,END)
         self.nitri.delete(0,END)
#----------------------------------------------
         
    def apagar2(self):
        phx = str(self.listbox9.get(ACTIVE))
        tempx = str(self.listbox10.get(ACTIVE))
        tempagx = str(self.listbox11.get(ACTIVE))
        condx = str(self.listbox12.get(ACTIVE))
        turbx = str(self.listbox13.get(ACTIVE))
        oxx = str(self.listbox14.get(ACTIVE))
        solix = str(self.listbox15.get(ACTIVE))
        colix = str(self.listbox16.get(ACTIVE))
        nitrix = str(self.listbox17.get(ACTIVE))
        coletax = str(self.listbox18.get(ACTIVE))
        profundx = str(self.listbox19.get(ACTIVE))
        
        self.cur.execute("DELETE FROM ph WHERE ph=?",[phx])
        self.conectar.commit()
        self.listbox9.delete(ANCHOR)
        self.cur.execute("DELETE FROM tempar WHERE tempar=?",[tempx])
        self.conectar.commit()
        self.listbox10.delete(ANCHOR)
        self.cur.execute("DELETE FROM tempag WHERE tempag=?",[tempagx])
        self.conectar.commit()
        self.listbox11.delete(ANCHOR)
        self.cur.execute("DELETE FROM condutelectre WHERE condutelectre=?",[condx])
        self.conectar.commit()
        self.listbox12.delete(ANCHOR)
        self.cur.execute("DELETE FROM turb WHERE turb=?",[turbx])
        self.conectar.commit()
        self.listbox13.delete(ANCHOR)
        self.cur.execute("DELETE FROM oxedis WHERE oxedis=?",[oxx])
        self.conectar.commit()
        self.listbox14.delete(ANCHOR)
        self.cur.execute("DELETE FROM solidtotal WHERE solidtotal=?",[solix])
        self.conectar.commit()
        self.listbox15.delete(ANCHOR)
        self.cur.execute("DELETE FROM colifortotal WHERE colifortotal=?",[colix])
        self.conectar.commit()
        self.listbox16.delete(ANCHOR)
        self.cur.execute("DELETE FROM nitritotal WHERE nitritotal=?",[nitrix])
        self.conectar.commit()
        self.listbox17.delete(ANCHOR)
        self.cur.execute("DELETE FROM coleta WHERE coleta=?",[coletax])
        self.conectar.commit()
        self.listbox18.delete(ANCHOR)
        self.cur.execute("DELETE FROM profundi WHERE profundi=?",[profundx])
        self.conectar.commit()
        self.listbox19.delete(ANCHOR)
#------------------------------------------------------------
#---------------------------------------------------------
    def salvar(self):
         global total
         total = self.lat.get(),self.log.get(),self.nome1.get(),self.data.get(),self.area.get(),self.uf.get(),self.cidade.get(),self.var.get()
         gravar = open("dadosSalvos.txt","a")
         salvar = str(total)
         gravar.write(salvar + "\n")
         gravar.close()
    #---------------------------------------------------------------------------Comados aba2
    def nova(self):
        self.nova_janela = Toplevel( width=1000, heigh=500)
        self.label26 = Label(self.nova_janela,text="Mais Parametros")
        self.label26.place(x=1,y=2)
        #-----------------------------------------
        scrollbar15 = Scrollbar(self.nova_janela)
        scrollbar15.place(x=670,y=200)
        self.listbox15 = Listbox(self.nova_janela,height=10,width=7)
        self.listbox15.place(x=570,y=200)
        self.listbox15.config(yscrollcommand=scrollbar15.set)
        scrollbar15.config(command=self.listbox15.yview)
        #-------------------------------uf
        scrollbar16 = Scrollbar(self.nova_janela)
        scrollbar16.place(x=908,y=200)
        self.listbox16 = Listbox(self.nova_janela,height=10,width=7)
        self.listbox16.place(x=810,y=200)
        self.listbox16.config(yscrollcommand=scrollbar16.set)
        scrollbar16.config(command=self.listbox16.yview)
#----------------------------------------------------------------------



       
root = Tk()
root.title("GeoÁguas")
root.geometry()
Main(root)
root.mainloop()
